import os

def timeOrder(file):
    dataDict = {}
    datarepeat = {}
    with open("data_"+file+".txt","r")as f:
        for i in f.readlines():
            tempList = i.split()
            if len(tempList) == 4:
                # print(i)
                # print(i.split())
                firstStr=i
                workerNu=i.split()[0]
                taskNu = i.split()[1]
            else:
                if int(tempList[0]) in dataDict:
                    datarepeat.update({int(tempList[0]):tempList})
                else:
                    dataDict.update({int(tempList[0]):tempList})
    data = sorted(dataDict)
    # print(datarepeat)
    folderNu=[1,2,3,4,5,6,7,8,9,10]
    for foNu in folderNu:
        destPath = "../gMission_cap"+str(foNu)
        if not os.path.exists(destPath):
            os.mkdir(destPath)

        outputFileName = os.path.join(destPath,"data_"+file+"_s.txt")    
        #修改总共节点数
        firstLine = firstStr.split()
        firstLine[3] = str(int(firstLine[0])*foNu+int(firstLine[1]))
        tempStr = ''
        for item in firstLine:
            tempStr +=item+' '
        tempStr+='\n'
        # with open("data_"+file+"_s.txt",'w') as f:
        with open(outputFileName,'w') as f:
            f.write(tempStr)
            for i in data:
                outstr = ''
                nodeType = dataDict[i][1]
                if nodeType=="w":
                    dataDict[i][5]=str(foNu)
                for j in dataDict[i]:
                    outstr +=j+' '
                outstr+='\n'
                f.write(outstr)
                if i in datarepeat:#将时间重复的数据写入
                    outstr = ''
                    for j in datarepeat[i]:
                        outstr +=j+' '
                    f.write(outstr)

if __name__=='__main__':
    fileName=["00","01","02","03","04","05","06","07","08","09"]
    # fileName=["00"]
    for i in fileName:
        timeOrder(i)